package com.bigbigrain.jiagou.design.command;

import com.bigbigrain.jiagou.design.command.impl.LightOffCommand;
import com.bigbigrain.jiagou.design.command.impl.LightOnCommand;
import com.bigbigrain.jiagou.design.command.impl.TvOffCommand;
import com.bigbigrain.jiagou.design.command.impl.TvOnCommand;

/**
 * @description:
 * @author: B1gB1gRA1n
 * @create: 2020-6-1 09:47
 **/
public class Client {
    public static void main(String[] args) {
        //使用命令模式，完成通过遥控器对电灯的操作
        //创建电灯的对象（接受者）
        LightReceiver lightReceiver = new LightReceiver();
        //创建电灯相关的开关命令
        LightOnCommand lightOnCommand = new LightOnCommand(lightReceiver);
        LightOffCommand lightOffCommand = new LightOffCommand(lightReceiver);

        //创建遥控器
        RemoteController remoteController = new RemoteController();
        //给遥控器设置命令，no=0是电灯的开和关操作
        remoteController.setCommand(0,lightOnCommand,lightOffCommand);
        System.out.println("++++++按下灯的开按钮+++++");
        remoteController.onButtonWasPushed(0);
        System.out.println("++++++按下灯的关按钮+++++");
        remoteController.offButtonWasPushed(0);
        System.out.println("++++++按下撤销按钮+++++");
        remoteController.undoButtonWasPushed();

        System.out.println("++++++++使用遥控器操作电视机++++++++");
        TvReceiver tvReceiver = new TvReceiver();
        TvOnCommand tvOnCommand = new TvOnCommand(tvReceiver);
        TvOffCommand tvOffCommand = new TvOffCommand(tvReceiver);
        //给遥控器设置命令，no=1是电视机的开和关操作
        remoteController.setCommand(1, tvOnCommand, tvOffCommand);
        System.out.println("++++++++按下电视机的开按钮++++++++");
        remoteController.onButtonWasPushed(1);
        System.out.println("+++++++++按下电视机的关按钮+++++++");
        remoteController.offButtonWasPushed(1);
        System.out.println("+++++++++按下撤销按钮+++++++");
        remoteController.undoButtonWasPushed();
    }
}
